home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / tbbs / tigerfix.zip / WTCHNEWS.PRG < prev    next >
Text File  |  1996-05-22  |  30KB  |  777 lines

  1. *--------------------------------------------------------------------------*
  2. *--------------------------------------------------------------------------*
  3. *                                                                          *
  4. *                                PRUNEIN                                   *
  5. *                                                                          *
  6. *                      (c) 1993 by Bernal Schooley                         *
  7. *                          and Advanced Designs                            *
  8. *                                                                          *
  9. *    This program is being released as SHAREware!  Please REGISTER it if   *
  10. *    you decide to use it in ANY way.  A LOT of work has gone into this    *
  11. *    and is available to you now because OTHER people have SUPPORTED the   *
  12. *    development of this and other TDBS software by Advanced Designs.      *
  13. *                                                                          *
  14. *    I ask YOU to be among those who support this and future developments  *
  15. *    by REGISTERING PRUNE.  Registration is ONLY $25.00 and will allow     *
  16. *    you to recieve technical support and will give you a feeling of       *
  17. *    satisfaction in knowing that your supporting the efforts of a         *
  18. *    struggling third party TDBS developer. ;)                             *
  19. *                                                                          *
  20. *                                     Thank you!                           *
  21. *                                     --Bernal Schooley                    *
  22. *                                       Advanced Designs                   *
  23. *                                       217-344-9145     (voice)           *
  24. *                                       217-367-1710     (support bbs)     *
  25. *                                       bernal@unity.com (internet)        *
  26. *                                                                          *
  27. *--------------------------------------------------------------------------*
  28. *--------------------------------------------------------------------------*
  29. *                                                                          *
  30. *    If you need additional function added to this program and are unable, *
  31. * or simply don't have enough time, to do it yourself, you may call        *
  32. * Bernal Schooley for a quote on custom programming services!  Average     *
  33. * hourly rates for short to medium term contracts are $40.00.  This amount *
  34. * can vary based on complexity, onsite or offsite, and length of overall   *
  35. * contract.                                                                *
  36. *                                                                          *
  37. *--------------------------------------------------------------------------*
  38. *--------------------------------------------------------------------------*
  39.  
  40.  
  41. CLEAR
  42.  
  43. ** Load path variables from the TIGER.CTL file
  44.  
  45.    FOPEN handle "\TBBS\TIGER.CTL" 10 FMAXLEN()
  46.    FLFIND handle pos "UUCPIN:" 1
  47.    FLREAD handle bytes data
  48.    uucpin = UPPER(LTRIM(RTRIM(CRTRIM(SUBSTR(data,AT("UUCPIN:",UPPER(data))+8)))))
  49.    FSEEK handle pos 0 0
  50.    FLFIND handle pos "UUCPIN-STAGE:" 1
  51.    FLREAD handle bytes data
  52.    stagein = UPPER(LTRIM(RTRIM(CRTRIM(SUBSTR(data,AT("UUCPIN-STAGE:",UPPER(data))+14)))))
  53.    FSEEK handle pos 0 0
  54.    FLFIND handle pos "HOST:" 1
  55.    FLREAD handle bytes data
  56.    host = UPPER(LTRIM(RTRIM(CRTRIM(SUBSTR(data,AT("HOST:",UPPER(data))+6)))))
  57.    FSEEK handle pos 0 0
  58.    FLFIND handle pos "UUCPNAME:" 1
  59.    FLREAD handle bytes data
  60.    uucpname = UPPER(LTRIM(RTRIM(CRTRIM(SUBSTR(data,AT("UUCPNAME:",UPPER(data))+10)))))
  61.    FCLOSE handle
  62.  
  63.  
  64. ** Check for TIGRBUSY or MAILBUSY flags
  65.  
  66.    DO WHILE .T.
  67.       IF FILE(stagein+"TIGRBUSY") .OR. FILE(uucpin+"TIGRBUSY")
  68.          CLEAR
  69.          ? "Directories in use..."
  70.          ? "PRUNEOUT waiting on TIGRBUSY flags..."
  71.       ELSE
  72.          IF FILE(stagein+"MAILBUSY") .OR. FILE(uucpin+"MAILBUSY")
  73.             CLEAR
  74.             ? "Directories in use..."
  75.             ? "PRUNEOUT waiting on MAILBUSY flags..."
  76.          ELSE
  77.             EXIT
  78.          ENDIF
  79.       ENDIF
  80.       ?
  81.       ? "(Press [A] to abort or [D] to delete busy flags and begin.)"
  82.       char = INKEY(10)
  83.       IF char = 65 .OR. char = 97
  84.          QUIT
  85.       ENDIF
  86.       IF char = 68 .OR. char = 100
  87.          IF FILE(stagein+"TIGRBUSY")
  88.             temp = stagein + "TIGRBUSY"
  89.             ERASE &temp
  90.          ENDIF
  91.          IF FILE(uucpin+"TIGRBUSY")
  92.             temp = uucpin + "TIGRBUSY"
  93.             ERASE &temp
  94.          ENDIF
  95.          IF FILE(stagein+"MAILBUSY")
  96.             temp = stagein + "MAILBUSY"
  97.             ERASE &temp
  98.          ENDIF
  99.          IF FILE(uucpin+"MAILBUSY")
  100.             temp = uucpin + "MAILBUSY"
  101.             ERASE &temp
  102.          ENDIF
  103.          EXIT
  104.       ENDIF
  105.    ENDDO
  106.  
  107. ** All clear... write busy files to lock directories and begin
  108.  
  109.    ? "PRUNEIN - Working..."
  110.    in_busy   = uucpin+"MAILBUSY"
  111.    out_busy  = stagein+"MAILBUSY"
  112.    FCREATE handle &in_busy 3  
  113.    FCLOSE handle
  114.    FCREATE handle &out_busy 3
  115.    FCLOSE handle
  116.  
  117. ** Load "keep" array from PRUNE.CFG for use while pruning
  118.  
  119.    max = 20
  120.    PUBLIC keep[max]                                      
  121.    keep[1] = "From:"
  122.    keep[2] = "Reply-To:"
  123.    keep[3] = "Subject:"
  124.    
  125.    FOPEN handle PRUNE.CFG 10 FMAXLEN()
  126.    FLFIND handle pos "PRUNE-METHOD:" 1
  127.    FLREAD handle bytes data
  128.    method = UPPER(LTRIM(RTRIM(CRTRIM(SUBSTR(data,AT("PRUNE-METHOD:",UPPER(data))+14)))))
  129.    FSEEK handle pos 0 0
  130.    FLFIND handle pos "ACCOUNTING:" 1
  131.    FLREAD handle bytes data
  132.    accounting = UPPER(LTRIM(RTRIM(CRTRIM(SUBSTR(data,AT("ACCOUNTING:",UPPER(data))+12)))))
  133.    ** More variables could be loaded from the CFG file by adding code like
  134.    ** the following:
  135.    *
  136.    * FSEEK handle pos 0 0
  137.    * FLFIND handle pos "[another keyword]:" 1
  138.    * FLREAD handle bytes data
  139.    * [new variable] = UPPER(LTRIM(RTRIM(CRTRIM(SUBSTR(data,AT("[keyword as above]:",UPPER(data))+14)))))
  140.    
  141.    FSEEK handle pos 0 0                                       
  142.    FLFIND handle pos "KEEP:" 1
  143.    FLREAD handle bytes data
  144.    FLREAD handle bytes data
  145.    top = 3
  146.    DO WHILE data # "ENDKEEP:" .AND. bytes > 0 .AND. top < max
  147.       top = top + 1
  148.       keep[top] = LTRIM(RTRIM(CRTRIM(data)))
  149.       FLREAD handle bytes data
  150.    ENDDO
  151.    FCLOSE handle
  152.  
  153.  
  154. ** Perform pruning on all .D files in the stagein directory
  155.  
  156.    xfile  = FINDFIRST(fnd_nxt, stagein+"*.X")
  157.    xfilep = stagein+xfile
  158.    DO WHILE LEN(xfile) > 0
  159.  
  160.     ** open the .X file
  161.  
  162.       FOPEN handle &xfilep 10 FMAXLEN()/2
  163.  
  164.       ** Read "F" line to find the file name
  165.  
  166.       FLFIND handle pos "F "
  167.       IF pos < 1
  168.          FCLOSE handle
  169.          tofile = STUFF(xfilep,AT(".X",xfilep),2,".X!!")
  170.          RENAME &xfilep TO &tofile
  171.          xfile  = FINDNEXT(fnd_nxt)
  172.          xfilep = stagein+xfile
  173.          LOOP
  174.       ENDIF
  175.  
  176.       FLREAD handle bytes data
  177.       data = RTRIM(CRTRIM(data))
  178.       IF LEN(data) < 6 .OR. .NOT. "D." $ UPPER(data)
  179.          FCLOSE handle
  180.          tofile = STUFF(xfilep,AT(".X",xfilep),2,".X!!")
  181.          RENAME &xfilep TO &tofile
  182.          xfile  = FINDNEXT(fnd_nxt)
  183.          xfilep = stagein+xfile
  184.          LOOP
  185.       ENDIF
  186.  
  187.       ** calculate the .D file name
  188.  
  189.       dfile = RTRIM(CRTRIM(SUBSTR(data,AT("D.",UPPER(data))+2)))
  190.  
  191.       ** Calculate the first letter of a .D waffle file *******
  192.     
  193.       y = 1
  194.       tryhost = .T.
  195.       tryuucp = .T.
  196.       lenh = LEN(host)
  197.       lenu = LEN(uucpname)
  198.        
  199.       DO WHILE y > 0
  200.          IF y <= lenh .AND. tryhost
  201.             IF UPPER(LEFT(dfile,1)) = SUBSTR(host,y,1)
  202.                dfile = SUBSTR(dfile,2)
  203.                y = y + 1
  204.                LOOP
  205.             ELSE            
  206.                IF tryuucp
  207.                   tryhost = .F.
  208.                ELSE
  209.                   exit
  210.                ENDIF 
  211.             ENDIF
  212.          ELSE
  213.             tryhost = .F.
  214.             IF .NOT. tryuucp
  215.                exit
  216.             ENDIF    
  217.          ENDIF
  218.          IF y <= lenu .AND. tryuucp
  219.             IF UPPER(LEFT(dfile,1)) = SUBSTR(uucpname,y,1)
  220.                dfile = SUBSTR(dfile,2)
  221.                y = y + 1
  222.                LOOP
  223.             ELSE
  224.                IF tryhost
  225.                   tryuucp = .F.
  226.                ELSE
  227.                   exit
  228.                ENDIF
  229.             ENDIF
  230.          ELSE    
  231.             tryuucp = .F.
  232.             IF .NOT. tryhost
  233.                exit
  234.             ENDIF    
  235.          ENDIF
  236.       ENDDO
  237.       
  238.       DO WHILE "." $ dfile   
  239.          dfile = STUFF(dfile,AT(".",dfile),1,"")
  240.       ENDDO
  241.                           
  242.       x = LEN(dfile)
  243.       y = 1
  244.       char_val = 0
  245.       
  246.       DO WHILE y <= 16 .AND. x > 0
  247.          IF ISLOWER(SUBSTR(dfile,x,1))
  248.             char_val = char_val + y
  249.          ENDIF
  250.          y = y * 2
  251.          x = x - 1
  252.       ENDDO
  253.       
  254.       IF char_val < 10
  255.          dfile = CHR(char_val+48)+dfile+".D"
  256.       ELSE
  257.          dfile = CHR(char_val+55)+dfile+".D"
  258.       ENDIF
  259.       
  260.       ** End of calculation - dfile now has the correct name (hopefully)
  261.  
  262.       ** verify existance of .D file
  263.  
  264.       dfilep = stagein+dfile
  265.       IF .NOT. FILE(dfilep)
  266.          FCLOSE handle
  267.          tofile = STUFF(xfilep,AT(".X",xfilep),2,".X!!")
  268.          RENAME &xfilep TO &tofile
  269.          xfile  = FINDNEXT(fnd_nxt)
  270.          xfilep = stagein+xfile
  271.          LOOP
  272.       ENDIF
  273.  
  274.       IF accounting = "YES"
  275.       
  276.          ** load in the "C" line from the .X file
  277.    
  278.          FSEEK handle pos 0 0
  279.          FLFIND handle pos "C "
  280.          IF pos < 1 .OR. FSIZE(dfilep) = 0
  281.             FCLOSE handle        
  282.             tofile = STUFF(xfilep,AT(".X",xfilep),2,".X!!")
  283.             RENAME &xfilep TO &tofile
  284.             tofile = STUFF(dfilep,AT(".D",xfilep),2,".D!!")
  285.             RENAME &xfilep TO &tofile
  286.             xfile  = FINDNEXT(fnd_nxt)
  287.             xfilep = stagein+xfile
  288.             LOOP
  289.          ENDIF
  290.          FLREAD handle bytes data
  291.  
  292.          ** Check to see if it is mail
  293.    
  294.          IF "RMAIL" $ UPPER(data)
  295.             
  296.             data = UPPER(RTRIM(LTRIM(CRTRIM(SUBSTR(data,9)))))
  297.  
  298.             ** Loop if more than one name is in the RMAIL line
  299.             
  300.             DO WHILE LEN(data) > 0
  301.  
  302.                ** strip out the name from the rmail line
  303.      
  304.                IF " " $ data .OR. "@" $ data
  305.                   IF "@" $ data
  306.                      name = SUBSTR(data,1,AT("@",data)-1)
  307.                      IF " " $ data
  308.                         data = SUBSTR(data,AT(" ",data)+1)
  309.                      ENDIF
  310.                   ELSE
  311.                      name = SUBSTR(data,1,AT(" ",data)-1)
  312.                      data = SUBSTR(data,AT(" ",data)+1)
  313.                   ENDIF
  314.                ELSE
  315.                   name = data
  316.                   data = ""   
  317.                ENDIF
  318.                IF "!" $ name
  319.                   name = SUBSTR(name,RAT("!",name)+1)
  320.                ENDIF
  321.                DO WHILE "." $ name
  322.                   name = STUFF(name,AT(".",name),1," ")
  323.                ENDDO
  324.                
  325.                *---------------------------------------------------------*
  326.                *                                                         *
  327.                * This is where you would add code if you want to perform *
  328.                * accounting functions.  At this point the field "name"   *
  329.                * contains the name of the user on your system that this  *
  330.                * message is for.  You could at this time store that and  *
  331.                * after looking up the size of dfilep and xfilep store    *
  332.                * that as well.  You would need to put these in a         *
  333.                * database because you can not access the users userlog   *
  334.                * record at this time.  You could create a program that   *
  335.                * is autoexecuted at logon which would lookup any new     *
  336.                * accounting data records and adjust the users netmail    *
  337.                * at that time.                                           *
  338.                *                                                         *
  339.                * PS: There is code here that will attempt to grab each   *
  340.                * name in the actual "C" line.  There may be more than    *
  341.                * one in the case of mailing lists for instance.  This    *
  342.                * code is not fully tested for such senarios and would    *
  343.                * need to have a full set of test performed after you add *
  344.                * code and turn on the accounting features.               *
  345.                *                                                         *
  346.                *---------------------------------------------------------*
  347.             
  348.             ENDDO               
  349.          ENDIF
  350.       ENDIF
  351.       
  352.       ** Close the .X file
  353.       
  354.       FCLOSE handle      
  355.  
  356.       ** Prepair to process the .D file and rename to show current file
  357.       ** being processed.
  358.  
  359.       dback  = SUBSTR(dfile,1,AT(".",dfile))+"D##"
  360.       dbackp = stagein+dback
  361.  
  362.       ** Rename .d file to .d## and create new .d file of same name
  363.                                       
  364.       RENAME &dfilep TO &dbackp
  365.  
  366.       dfilep = uucpin+dfile
  367.       FOPEN handle &dbackp 10 FMAXLEN()/3
  368.       FLREAD handle bytes data
  369.       FCREATE newhandle &dfilep 13 0 FMAXLEN()/2
  370.       
  371.       ** Skip the first line if it is a cunbatch line sometimes sent
  372.       ** even on uncompress news files
  373.       
  374.       IF UPPER(LEFT(data,3)) = "CUN"
  375.          FLREAD handle bytes data
  376.       ENDIF
  377.       
  378.       ** If this is a news file the line will have the rnews line in it
  379.       
  380.       IF UPPER(LEFT(data,8)) # "#! RNEWS"
  381.   
  382.          ** Mail file processing
  383.          ? "MAIL: "+dfile
  384.  
  385.          header = .T.
  386.          DO WHILE bytes > 0
  387.             
  388.             ** for speed keep track of when the header is being processed
  389.          
  390.             IF header .AND. LEN(RTRIM(CRTRIM(data))) > 0
  391.                
  392.                ** Header lines will always begin with a header field
  393.                ** name or with a white space character of space or tab.
  394.                ** White space lines we'll have to handle them the same
  395.                ** as was done on the previous field line.
  396.  
  397.                IF data = " " .OR. data = CHR(9)       
  398.                   IF lastprune
  399.                      
  400.                      ** If method is HIDE, write the line with a CHR(1)
  401.                      ** preceeding it.  TBBS will then hide the lines
  402.                      ** from display except in the Quoting function.
  403.                      
  404.                      IF method = "HIDE"
  405.                         FLWRITE newhandle out CHR(1)
  406.                         FLWRITE newhandle out data
  407.                      ENDIF
  408.                   ELSE
  409.                      FLWRITE newhandle out data
  410.                   ENDIF
  411.                ELSE
  412.  
  413.                   *---------------------------------------------------------*
  414.                   *                                                         *
  415.                   * This is where you would add code if you want to look    *
  416.                   * for information in the mail headers.  Each pass through *
  417.                   * here has a line of the header in the "data" field.      *
  418.                   *                                                         *
  419.                   * For example you could have:                             *
  420.                   *                                                         *
  421.                   * IF data = "To:" .AND. "FTPMAIL" $ data                  *
  422.                   *    datarequest = .T.                                    *
  423.                   * ENDIF                                                   *
  424.                   *                                                         *
  425.                   *---------------------------------------------------------*
  426.                      
  427.                    
  428.                   ** For error recovery make sure this file has not been
  429.                   ** processed before, but do the whole thing anyway to
  430.                   ** make sure everything is marked properly.
  431.                    
  432.                   IF data # CHR(1)              
  433.                               
  434.                      ** if this is a header field line then strip the field
  435.                      ** name off and look it up in the keep array.  If found
  436.                      ** write it out as normal, otherwise prune it.
  437.                      
  438.                      temp = SUBSTR(data,1,AT(":",data))
  439.                      IF ASCAN(keep,temp) # 0
  440.                         FLWRITE newhandle out data
  441.                         lastprune = .F.
  442.                      ELSE
  443.                         IF method = "HIDE"
  444.                            FLWRITE newhandle out CHR(1)
  445.                            FLWRITE newhandle out data
  446.                         ENDIF
  447.                         lastprune = .T.
  448.                      ENDIF
  449.                   ELSE
  450.                      FLWRITE newhandle out data
  451.                   ENDIF
  452.                ENDIF
  453.             ELSE
  454.  
  455.                *---------------------------------------------------------*
  456.                *                                                         *
  457.                * This is where you would add code if you want to look    *
  458.                * for information in the body of a mail message.  On each *
  459.                * pass "data" has one line of the message body.           *
  460.                *                                                         *
  461.                * For example you could have:                             *
  462.                *                                                         *
  463.                * IF datarequest .AND. "SEND INDEX" $ data                *
  464.                *    FLWRITE newhandle out "GET INDEX.LST"+CHR(10)        *
  465.                * ENDIF                                                   *
  466.                *                                                         *
  467.                *---------------------------------------------------------*
  468.  
  469.                FLWRITE newhandle out data
  470.                header = .F.
  471.             ENDIF
  472.             FLREAD handle bytes data
  473.          ENDDO
  474.       ELSE
  475.     
  476.          ** News file processing
  477.          ? "NEWS: "+dfile
  478.  
  479.          DO WHILE bytes > 0
  480.  
  481.             ** To process news files a temporary file must be used in order
  482.             ** to determine the full size of the news message before writing
  483.             ** the first line of the .D news message header.
  484.             ** Each news message must be temporarily written to this temp
  485.             ** file then once the full size is determined and the header
  486.             ** line is written to the .d then the temp file may be copied
  487.             ** back to the new .d file.
  488.  
  489.             FCREATE temphandle PRUNE.$$$ 13 0 FMAXLEN()
  490.             header = .T.
  491.             FLREAD handle bytes data
  492.             DO WHILE data # "#! rnews" .AND. bytes > 0
  493.    
  494.                ** for speed keep track of when the header is being processed
  495.    
  496.                IF header .AND. LEN(RTRIM(CRTRIM(data))) > 0
  497.                   
  498.                   ** Header lines will always begin with a header field
  499.                   ** name or with a white space character of space or tab.
  500.                   ** White space lines we'll have to handle them the same
  501.                   ** as was done on the previous field line.
  502.  
  503.                   IF data = " " .OR. data = CHR(9)
  504.                      IF lastprune   
  505.                      
  506.                         ** If method is HIDE, write the line with a CHR(1)
  507.                         ** preceeding it.  TBBS will then hide the lines
  508.                         ** from display except in the Quoting function.
  509.          
  510.                         IF method = "HIDE"
  511.                            FLWRITE temphandle out CHR(1)
  512.                            FLWRITE temphandle out data
  513.                         ENDIF
  514.                      ELSE
  515.                         FLWRITE temphandle out data
  516.                      ENDIF
  517.                   ELSE
  518.                      
  519.                      ** For error recovery make sure this file has not been
  520.                      ** processed before, but do the whole thing anyway to
  521.                      ** make sure everything is marked properly.
  522.               
  523.                      IF data # CHR(1)              
  524.                                  
  525.                         ** if this is a header field line then strip the field
  526.                         ** name off and look it up in the keep array.  If found
  527.                         ** write it out as normal, otherwise prune it.
  528.                         
  529.                         temp = SUBSTR(data,1,AT(":",data))
  530.                         IF ASCAN(keep,temp) # 0
  531.                            FLWRITE temphandle out data
  532.                            lastprune = .F.
  533.                         ELSE
  534.                            IF method = "HIDE"
  535.                               FLWRITE temphandle out CHR(1)
  536.                               FLWRITE temphandle out data
  537.                            ENDIF
  538.                            lastprune = .T.
  539.                         ENDIF
  540.                      ELSE
  541.                         FLWRITE temphandle out data
  542.                      ENDIF
  543.                  ENDIF
  544.                ELSE
  545.                   FLWRITE temphandle out data
  546.                   header = .F.
  547.                ENDIF
  548.                FLREAD handle bytes data
  549.             ENDDO
  550.             
  551.             ** This is where the news header line is written with the size
  552.             ** of the new message, then the temp file is copied into the
  553.             ** new .d file.
  554.             
  555.             ?? "."
  556.             FCLOSE temphandle
  557.             FLWRITE newhandle out "#! rnews "+LTRIM(STR(FSIZE("PRUNE.$$$")))+CHR(10)
  558.             FOPEN temphandle PRUNE.$$$ 10 FMAXLEN()
  559.             FLREAD temphandle in data
  560.             DO WHILE in > 0
  561.                 FLWRITE newhandle out data
  562.                 FLREAD temphandle in data
  563.             ENDDO
  564.             FCLOSE temphandle
  565.          ENDDO
  566.  
  567.       ENDIF
  568.       
  569.       ** Close and move .X file
  570.  
  571.       ERASE PRUNE.$$$
  572.       FCLOSE handle
  573.       FCLOSE newhandle
  574.       ERASE &dbackp
  575.       
  576.       tofile = uucpin+xfile
  577.       COPY FILE &xfilep TO &tofile
  578.       ERASE &xfilep
  579.  
  580.       ** Get next .X file
  581.       
  582.       xfile  = FINDNEXT(fnd_nxt)
  583.       xfilep = stagein+xfile
  584.  
  585.    ENDDO
  586.  
  587. ** Remove busy flags
  588.  
  589.    ERASE &in_busy
  590.    ERASE &out_busy
  591.  
  592. *--------------------------------------------------------------------------*
  593. *--------------------------------------------------------------------------*
  594. *                                                                          *
  595. * WARRANTY / DISCLAIMER:  PRUNE IS DISTRIBUTED ON AN "AS IS" BASIS ONLY,   *
  596. *  WITHOUT WARRANTY.  NEITHER ADVANCED DESIGNS, NOR BERNAL SCHOOLEY, SHALL *
  597. *  HAVE LIABILITY OR RESPONSIBILITY TO ANY PERSON OR ENTITY WITH RESPECT   *
  598. *  TO LIABILITY, LOSS, OR DAMAGE CAUSED OR ALLEGED TO BE CAUSED BY THIS    *
  599. *  SOFTWARE.  THIS INCLUDES, BUT IS NOT LIMITED TO, ANY INTERRUPTION OF    *
  600. *  SERVICE, LOSS OF BUSINESS OR ANTICIPATORY PROFITS, OR CONSEQUENTIAL     *
  601. *  DAMAGE RESULTING FROM THE USE OF THIS SOFTWARE.                         *
  602. *                                                                          *
  603. *--------------------------------------------------------------------------*
  604. *--------------------------------------------------------------------------*
  605. ************************WTCHNEWS.PRG  (c) David Rance*************************
  606. *                   Source released to the Public Domain                     *
  607. *                                                                            *
  608. *   A quick 'n' dirty program for Rick Sande (and others) to check incoming  *
  609. *   .D files for over-long newsgroup lines and to delete the file if too     *
  610. *   long.                                                                    *
  611. *   1st May, 1996   - Version 0.2. First version deleted the whole packet if *
  612. *                     only one message was bad! Rectified.                   *
  613.  
  614. public tigerpath
  615. tigerpath=""
  616.  
  617. ? "WatchNews ver. 0.2  -  checks incoming .D files for over-long newsgroup lines"
  618. ? "(c) 1996 David Rance"
  619. ?
  620. SET ALTERNATE TO c:\tbbs\news.log APPEND
  621. set alternate on
  622. ctime=time()
  623. cdate=dtoc(date())
  624. ?
  625. ? "Processing Started: "+ctime+" "+cdate
  626.  
  627. do get_config                    && process config file
  628.  
  629. * Check for TIGER, quit if active, create MAILBUSY if not (this is in case
  630. * the program is used from a menu entry).
  631.  
  632. fopen handle1 (tigerpath+"tigrbusy") 0
  633.     if handle1 < 0          && if TIGRBUSY doesn't exist create MAILBUSY
  634.         fcreate handle1 (tigerpath+"mailbusy") 13
  635.         fclose handle1
  636.     else
  637.         ? "TIGER is active. Aborting"
  638.         dummy=inkey(2)
  639. ? "Finished!"
  640.         quit
  641.     endif
  642.  
  643. fname=findfirst(dta,tigerpath+"*.d")   && Search inbound for .D files
  644.    if len(fname)=0
  645.         ? "No files found to process"
  646. ? "Finished!"
  647.         dummy=inkey(2)
  648.         erase (tigerpath+"mailbusy")
  649.         quit
  650.     endif
  651.  
  652.     do while len(fname)#0
  653.         do proc_file
  654.         fname=findnext(dta)
  655.     enddo
  656.  
  657.     ? "Finished!"
  658.     ?
  659.     dummy=inkey(2)
  660.     erase (tigerpath+"mailbusy")
  661.                             **** END MAIN ****
  662.  
  663.  
  664. PROCEDURE proc_file
  665.  
  666. c=0
  667.  
  668. ? "Processing "+fname                       && Open .D file
  669. fname=substr(fname,1,at(".",fname)-1)+".D"
  670. fopen handle1 (tigerpath+fname) 10 1024
  671.     if handle1 < 0                          && Loop back if it can't be opened
  672.         ?? " - can't be opened. Continuing..."
  673.         return
  674.     endif
  675. flread handle1 size record
  676.         if at("#! rnews",record)#1          && If not "#! rnews" it's not
  677.             ?? " - is not news"             && a news message so exit
  678.             fclose handle1
  679.             return
  680.         endif
  681.  
  682. fcreate handle2 TEMPFILE.$$$ 13               && create temp. buffer file
  683. destname=substr(fname,1,at(".",fname))+"$$$"  && create temporary output file
  684. fcreate handle3 (tigerpath+destname) 13
  685. flwrite handle2 wsize record               && write first "#! rnews" line
  686. flread handle1 size record
  687.  
  688.     do while size > 0                      && do loop until end of file
  689.         if at("Newsgroups:",record)=1      && if Newsgroups line....
  690.             if size > 250                  && if greater than 250 bytes....
  691.                 ? "Message deleted"
  692. SET ALTERNATE TO c:\tbbs\newsfix\fix.log
  693. set alternate on
  694.  
  695.                 c=1                        && set flag
  696.             endif
  697.         endif
  698.         if at("#! rnews",record)=1         && if start of new message....
  699.                 if c#1                         && if flag not set ...
  700.                     fclose handle2
  701.                     fopen handle2 TEMPFILE.$$$ 10
  702.                         do while size > 0      && ... copy tempfile to dest file
  703.                             flread handle2 size newrecord
  704.                             flwrite handle3 size newrecord
  705.                         enddo
  706.                 endif
  707.             fclose handle2
  708.             erase handle2
  709.             fcreate handle2 TEMPFILE.$$$ 13
  710.             c=0
  711.         endif
  712.         flwrite handle2 wsize record
  713.         flread handle1 size record
  714.     enddo
  715. fclose handle1
  716. fclose handle2
  717.         if c#1                         && if flag not set
  718.             fopen handle2 TEMPFILE.$$$ 10
  719.             flread handle2 size newrecord
  720.                 do while size > 0      && and copy tempfile to dest file
  721.                     flwrite handle3 wsize newrecord
  722.                     flread handle2 size newrecord
  723.                 enddo
  724.             fclose handle2
  725.             erase handle2
  726.         endif
  727.     fclose handle3
  728.     erase (tigerpath+fname)
  729.     copy file (tigerpath+destname) to (tigerpath+fname)
  730.     erase (tigerpath+destname)
  731.     erase "TEMPFILE.$$$"
  732. return
  733.                     **** END Procedure proc_file ****
  734.  
  735.  
  736. PROCEDURE get_config
  737.  
  738. fopen handle1 wtchnews.cfg 10 128        && open config file
  739.     if handle1 < 0
  740.         ? "Couldn't find configuration file. Aborting."
  741.         dummy=inkey(2)
  742.         quit
  743.     endif
  744.  
  745. flread handle1 size record        && this bit taken from another program
  746.     do while size#0               && so left "do case" in even though there's
  747.         do case                   && only one option!
  748.             case at("TIGERFILES",record)=1
  749.                 tigerpath=ltrim(rtrim(crtrim(substr(record,11))))
  750.                     if right(tigerpath,1)#"\"
  751.                         tigerpath=tigerpath+"\"
  752.                     endif
  753.         endcase
  754.         flread handle1 size record
  755.     enddo
  756.  
  757. * Check that all necessary variables are initialised. Abort if any are missing.
  758.  
  759.     missing=""
  760.     do case
  761.         case len(tigerpath)=0
  762.             missing="TIGER inbound path"
  763.     endcase
  764.  
  765.     if len(missing)#0
  766.             ? missing+" is not defined. Aborting."
  767.             dummy=inkey(2)
  768.             ? "Finished!"
  769.             quit
  770.     endif
  771. fclose handle1                      && close the config file
  772. return
  773.                     **** END procedure get_config ****
  774. ****************************** END OF PROGRAM ********************************
  775. set alternate on
  776.  
  777.